var md_product=(function($,md_list){
    var app={
        listvalid:{
            rules: {
                caption: {
                    required: true,
                    maxlength:50
                }
            },
            messages: {
                caption: {
                    required: "分类名称不能为空",
                    maxlength: "分类名称不能大于50个字符"
                }
            }
        },
        initEvent:function(){
            $(".make_img").on("click",function(){
                var spu=$(this).attr("data-spu");
                var img=$(this).attr("data-img");
                md_common.postAjax('/admin/common/make_img',{'spu':spu,'img':img},function(result){
                    if(result.info=="success"){
                        alert("生成图成功!");
                    }
                    else{
                        alert("生成图失败，系统错误!");
                    }
                });
            });
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea#description_content', {
                    resizeType : 1,
                    width:"100%",
                    height:"400px",
                    allowPreviewEmoticons : false,
                    allowImageUpload : false
                });
            });
            $("#saveForm").unbind("click").on("click", function () {
                if ($("#list_form").valid()) {
                    var description=editor.html();
                    $("#description").val(description);
                    md_common.postAjax("/admin/productInfo/saveInfo",$("#list_form").serialize(),function(result){
                        if(result.info=="success"){
                            if(result.id){
                                $("#model_id").val(result.id);
                            }
                            //alert("保存成功！");
                            window.location.href= window.location.href;
                        }
                        else{
                            alert(result.info);
                        }
                    });
                }
            });
            $("#upload_products").on("click",function(){
                var id=$(this).attr("data-id");
                $("#upload_product_id").val(id);
                $("#upload_product").modal();
            });
            $("#upload_product_info").on("click",function(){
                var id=$("#upload_product_id").val();
                var model=$("#model").val();
                $('#upload_excel_form').ajaxForm({
                    url:'/admin/productInfo/upload',
                    type: 'post',
        　　　　　　dataType: 'json',
        　　　　　　data :{'productid':id},
        　　　　　　contentType: false,
        　　　　　　processData: false,
                    success: function (result, status){
                       if(result.info=="success"){
                           window.location.href=window.location.href;
                       }
                       else{
                            md_common.showMessage("上传失败！");
                       }
                    },
                    error: function (data, status, e){
                        md_common.showMessage("上传失败！");
                    }
                }).submit();
            })
        }
    }
    return $.extend(true, md_list, app);
})($,md_list||{});
if(typeof md_product!=undefined){
    $(function(){
        md_product.init();
    });
}

